package com.qfedu.knowledge.controller;

import com.qfedu.knowledge.entity.vo.ResultVO;
import com.qfedu.knowledge.service.IUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @ClassName UploadController
 * @Author ykx
 * @Date 2024/5/1 18:32
 * @Version 1.0
 */
@RequestMapping("/knowledge")
@RestController
public class UploadController {

    @Autowired
    private IUploadService uploadService;

    @PostMapping(value = "/upload")
    public ResultVO upload(@RequestParam("file") MultipartFile multipartFile, @RequestParam("questionId") Long questionId) throws IOException {
        return ResultVO.success(uploadService.upload(multipartFile, questionId));
    }

    @PostMapping("/importQuestion")
    public ResultVO importQuestion(@RequestParam("file") MultipartFile multipartFile) {
        return ResultVO.success(uploadService.importQuestion(multipartFile));
    }

    @PostMapping(value = "/upload/image")
    public ResultVO uploadImage(@RequestParam("file") MultipartFile multipartFile, @RequestParam("id") Long id) throws IOException {
        return ResultVO.success(uploadService.uploadImage(multipartFile, id));
    }

}
